<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="时间区间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          @change="handleTimestamp"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="20" class="mb8" style="padding:5px 20px">
        <el-button type="primary" plain>总车流量：{{totalTraffic}}</el-button>
        <el-button type="success" plain>进场总数：{{inNum}}</el-button>
        <el-button type="info" plain>出场总数：{{outNum}}</el-button>
    </el-row>
    <el-row :gutter="20" class="mb8" style="padding:5px 20px">
        <el-button type="primary" plain>总收费笔数：{{totalPay}}</el-button>
        <el-button type="primary" plain>总收费金额：{{totalMoney/100}}(元)</el-button>
        <el-button type="info" plain>抵用券金额：{{ticketMoney/100}}(元)</el-button>
        <el-button type="info" plain>抵用券时长：{{ticketTime}}(小时)</el-button>
    </el-row>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" fixed align="center" width="80">
        <template scope="scope">
          <span>{{scope.$index + 1}} </span>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="carType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pay_type" :value="scope.row.payMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="支付笔数" align="center" prop="payTotalCount"/>
      <el-table-column label="支付总额" align="center" prop="payTotalMoney">
        <template slot-scope="scope">
          <span>{{scope.row.payTotalMoney/100}}(元)</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
  import { clientUrl } from "@/api/client";

  export default {
    name: "index",
    dicts: ['pay_type'],
    data(){
      return{
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 弹出层标题
        open: false,
        // 日期范围
        dateRange:[],
        //列表
        dataList:[],
        // 总车流量
        totalTraffic: 0,
        // 进场总数
        inNum: 0,
        // 出场总数
        outNum: 0,
        // 总收费笔数
        totalPay: 0,
        // 总收费金额(分)
        totalMoney: 0,
        ticketMoney: 0,
        ticketTime: 0,
        // 查询参数
        queryParams: {
          url:'/api/wec/GetParkingFlowReport',
          serviceCode: 'getParkingFlowReport',
          startTime:undefined,
          endTime:undefined,
        },
      }
    },

    created() {
      this.resetQuery();
    },

    methods:{
      /** 查询列表 */
      getList() {
        this.loading = true;
        clientUrl(this.queryParams).then(response => {
          let data = JSON.parse(response.data.data)
          this.dataList = data.payDetailList;
          this.totalTraffic = parseInt(data.totalTraffic);
          this.inNum = parseInt(data.inNum);
          this.outNum = parseInt(data.outNum);
          this.totalPay = parseInt(data.totalPay);
          this.totalMoney = parseInt(data.totalMoney);
          this.ticketMoney = parseInt(data.ticketMoney);
          this.ticketTime = parseInt(data.ticketTime);
          this.loading = false;
        });
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.getList();
      },

      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.dateRange = [this.getCurrentMonthFirst(),this.getCurrentMonthLast()];
        this.handleTimestamp();
        this.handleQuery();
      },

      handleTimestamp(){
        this.queryParams.startTime = undefined;
        this.queryParams.endTime = undefined;
        if(this.dateRange == null || !this.dateRange.length>0) this.dateRange = [this.getCurrentMonthFirst(),this.getCurrentMonthLast()];
        if(this.dateRange)this.queryParams.startTime = this.appendFix(this.dateRange[0],1);
        if(this.dateRange)this.queryParams.endTime =  this.appendFix(this.dateRange[1],2);
      }
    }
  }
</script>

<style scoped>

</style>
